$(function () {

    // var form = layui.form;
    //添加表单的判断
    layui.form.verify({
        pass:[
            /^[\S]{6,12}$/
            ,'密码必须6到12位，且不能出现空格'
        ],
       rePwd: function(value) {
            if (value == $('[name=oldPwd]').val()) {
              return '新旧密码不能重复';
            }
        },
        rePwds: function (value) {
            if (value !== $('[name=newPwd]').val()) {
              return '两次密码不一致！'
            }
        }
    });
    //获取表单的数据
    $('.layui-form').on('submit', function (e) {
       e.preventDefault();
        $.ajax({
            type: "POST",
            url: "/my/updatepwd",
            data: $(this).serialize(),
            success: function (res) {
                console.log(res);
                if (res.status !== 0) {
                    return layui.layer.msg('更新失败请从新输入!')
                } else {
                    return  layer.alert('更新密码成功!请重新登录', function(index){
                        localStorage.removeItem('token')
                        window.parent.location.href='/denglu.html'
                        layer.close(index);
                      });       
                     
                }
            }
        });
    });
    $('#Reset').on('click', function () {
        e.preventDefault();
        $('.layui-form')[0].reset()

    })

})